package com;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;

public class HttpClientInboundHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
//        if (msg instanceof HttpContent) {
//            ctx.channel().disconnect();
//        }
////        ctx.channel().disconnect();
//        if (msg instanceof HttpResponse) {
//            HttpResponse response = (HttpResponse) msg;
//            System.out.println(response.getStatus() + " CONTENT_TYPE:" + response.headers().get(HttpHeaders.Names.CONTENT_TYPE));
//            System.out.println("recv: " + ctx.channel().hashCode());
//        }
////        ctx.channel().disconnect();
//        if (msg instanceof HttpContent) {
//            HttpContent content = (HttpContent) msg;
//            ByteBuf buf = content.content();
//            System.out.println("content: "+buf.readableBytes() + buf.toString(io.netty.util.CharsetUtil.UTF_8));
//            buf.release();
//        }
    }
}
